package com.itheima.health.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.vo.CheckGroupVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@SuppressWarnings("ALL")
/**
 * @Description :检查组管理
 * @author     :LD
 */
@RestController
@RequestMapping("checkGroup")
@Api(tags = "预约模块-检查组管理")
public class CheckGroupController {
    @Reference
    private CheckGroupService checkGroupService;

    @GetMapping("findAll")
    @ApiOperation(value = "查询所有检查组",notes = "查询所有检查组")
    public Result findAll(){
        List<CheckGroup> list = checkGroupService.findAll();
        return new Result(list);
    }

    @PostMapping("findPage")
    @ApiOperation(value = "检查组分页查询",notes = "根据条件分页查询检查组")
    @ApiImplicitParam(name = "queryPageBean",value = "分页参数封装",required = true,dataType = "QueryPageBean")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        Map map = checkGroupService.findPage(queryPageBean);
        return new Result(map);
    }

    @PostMapping("add")
    @ApiOperation(value = "添加检查组",notes = "添加检查组并关联添加检查项")
    @ApiImplicitParam(name = "checkGroupDto",value = "检查组信息",required = true,dataType = "CheckGroupDTO")
    public Result add(@RequestBody CheckGroupDTO checkGroupDTO){
        checkGroupService.add(checkGroupDTO);
        return new Result(true);
    }

    @GetMapping("findItemsAndIds/{id}")
    @ApiOperation(value = "查询绑定的检查项",notes = "查询绑定的检查项")
    @ApiImplicitParam(name="id",value = "检查组id",paramType = "path",dataType = "Integer")
    public Result findItemsAndIds(@PathVariable("id")Integer id){
        CheckGroupVO checkGroupVO = checkGroupService.findItemsAndIds(id);
        return new Result(checkGroupVO);
    }

    @PutMapping("edit")
    @ApiOperation(value = "修改检查组",notes = "修改检查组并关联修改检查项")
    @ApiImplicitParam(name = "checkGroupDto",value = "检查组信息",required = true,dataType = "CheckGroupDTO")
    public Result edit(@RequestBody CheckGroupDTO checkGroupDTO){
        checkGroupService.edit(checkGroupDTO);
        return new Result(true);
    }

    @DeleteMapping("deleteById/{id}")
    @ApiOperation(value = "删除检查组",notes = "根据组id删除检查组")
    @ApiImplicitParam(name = "id",value = "检查组id",paramType = "path",dataType = "Integer")
    public Result deleteById(@PathVariable("id")Integer id){
        CheckGroup checkGroup = new CheckGroup();
        checkGroup.setId(id);
        checkGroup.setIs_delete(1);
        checkGroupService.updateById(checkGroup);
        return new Result(true);
    }
}
